package com.liliang.utils;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class RandomUtil {
    
    //得到流水号
    public static String getliushuihao(String key){
        return SerialUtil.get(key);
    }


    //自增流水号
    public static void setliushuihao(String key) throws IOException {
        String s = getliushuihao(key);
        String after = s.substring(0, 3);
        String date = s.substring(3, 11);
        int i = Integer.parseInt(s.substring(11));
        SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
        String format = sdf.format(new Date());
        if (date.equals(format)){
            String a=++i+"";
            for (int j = a.length(); j < 5; j++) {
                a="0"+a;
            }
            SerialUtil.set(key,after+format+a);
        }else{
            SerialUtil.set(key,after+format+"00001");
        }

    }

}
